package fun.xiefeihong.video.list.entity

import org.springframework.security.core.GrantedAuthority
import org.springframework.security.core.authority.SimpleGrantedAuthority
import org.springframework.security.core.userdetails.UserDetails

class User implements UserDetails {

	String username
	String password
	List<Role> roles
	String name

	User() {
	}

	User(String username, String password, List<Role> roles, String name) {
		this.username = username
		this.password = password
		this.roles = roles
		this.name = name
	}

	@Override
	List<GrantedAuthority> getAuthorities() {
		def auths = []
		for(role in roles){
			auths << new SimpleGrantedAuthority(role.roleName)
		}
		auths
	}

	@Override
	String getUsername() {
		username
	}

	@Override
	boolean isAccountNonExpired() {
		true
	}

	@Override
	boolean isAccountNonLocked() {
		true
	}

	@Override
	boolean isCredentialsNonExpired() {
		true
	}

	@Override
	boolean isEnabled() {
		true
	}

}
